﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace CPPProject.Migrations
{
    public partial class UpdateCPPPartAndPartBin : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_CPPPart_CPPCompany_CompanyId",
                table: "CPPPart");

            migrationBuilder.DropForeignKey(
                name: "FK_CPPPart_CPPCompany_ForCompanyId",
                table: "CPPPart");

            migrationBuilder.DropIndex(
                name: "IX_CPPPart_CompanyId",
                table: "CPPPart");

            migrationBuilder.DropIndex(
                name: "IX_CPPPart_ForCompanyId",
                table: "CPPPart");

            migrationBuilder.DropColumn(
                name: "CompanyId",
                table: "CPPPart");

            migrationBuilder.DropColumn(
                name: "ForCompanyId",
                table: "CPPPart");

            migrationBuilder.DropColumn(
                name: "PType",
                table: "CPPPart");

            migrationBuilder.DropColumn(
                name: "Quantity",
                table: "CPPPart");

            migrationBuilder.AlterColumn<decimal>(
                name: "MaxCapacity",
                table: "CPPPlant",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(300)",
                oldMaxLength: 300,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "IType",
                table: "CPPPlant",
                maxLength: 10,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(300)",
                oldMaxLength: 300,
                oldNullable: true);

            migrationBuilder.AddColumn<long>(
                name: "ForCompanyId",
                table: "CPPPlant",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "TransAttr",
                table: "CPPPlant",
                maxLength: 500,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "PType",
                table: "CPPPartTrans",
                maxLength: 10,
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_CPPPlant_ForCompanyId",
                table: "CPPPlant",
                column: "ForCompanyId");

            migrationBuilder.AddForeignKey(
                name: "FK_CPPPlant_CPPCompany_ForCompanyId",
                table: "CPPPlant",
                column: "ForCompanyId",
                principalTable: "CPPCompany",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_CPPPlant_CPPCompany_ForCompanyId",
                table: "CPPPlant");

            migrationBuilder.DropIndex(
                name: "IX_CPPPlant_ForCompanyId",
                table: "CPPPlant");

            migrationBuilder.DropColumn(
                name: "ForCompanyId",
                table: "CPPPlant");

            migrationBuilder.DropColumn(
                name: "TransAttr",
                table: "CPPPlant");

            migrationBuilder.DropColumn(
                name: "PType",
                table: "CPPPartTrans");

            migrationBuilder.AlterColumn<string>(
                name: "MaxCapacity",
                table: "CPPPlant",
                type: "nvarchar(300)",
                maxLength: 300,
                nullable: true,
                oldClrType: typeof(decimal));

            migrationBuilder.AlterColumn<string>(
                name: "IType",
                table: "CPPPlant",
                type: "nvarchar(300)",
                maxLength: 300,
                nullable: true,
                oldClrType: typeof(string),
                oldMaxLength: 10,
                oldNullable: true);

            migrationBuilder.AddColumn<long>(
                name: "CompanyId",
                table: "CPPPart",
                type: "bigint",
                nullable: false,
                defaultValue: 0L);

            migrationBuilder.AddColumn<long>(
                name: "ForCompanyId",
                table: "CPPPart",
                type: "bigint",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "PType",
                table: "CPPPart",
                type: "nvarchar(10)",
                maxLength: 10,
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "Quantity",
                table: "CPPPart",
                type: "decimal(18,2)",
                nullable: false,
                defaultValue: 0m);

            migrationBuilder.CreateIndex(
                name: "IX_CPPPart_CompanyId",
                table: "CPPPart",
                column: "CompanyId");

            migrationBuilder.CreateIndex(
                name: "IX_CPPPart_ForCompanyId",
                table: "CPPPart",
                column: "ForCompanyId");

            migrationBuilder.AddForeignKey(
                name: "FK_CPPPart_CPPCompany_CompanyId",
                table: "CPPPart",
                column: "CompanyId",
                principalTable: "CPPCompany",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_CPPPart_CPPCompany_ForCompanyId",
                table: "CPPPart",
                column: "ForCompanyId",
                principalTable: "CPPCompany",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }
    }
}
